<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<base href="<%=basePath%>">
<title>产品添加</title>


<%@ include file="/WEB-INF/jsp/common/common.jsp"%>
<script src="js/jquery.validate.js" type="text/javascript"></script>
<script src="js/jquery.divbox.js" type="text/javascript"></script>
<script src="js/json2.js" type="text/javascript"></script>
<style type="text/css">
.input_text {
	width: 250px;
}

.select_1 {
	width: 250px;
}

input.fieldError {
	border: 1px solid #ffb042;
	background-color: #fffbf5;
}

textarea.fieldError {
	border: 1px solid #ffb042;
	background-color: #fffbf5;
}

label.fieldError {
	line-height: 23px;
	color: #ffb042;
	padding-left: 6px;
}
</style>
<script type="text/javascript">
//自定义map功能
function Map(){
  this.elements = new Array();
   //获取MAP元素个数
   this.size = function() {
       return this.elements.length;
   };
   //判断MAP是否为空
   this.isEmpty = function() {
       return (this.elements.length < 1);
   };
   //删除MAP所有元素
   this.clear = function() {
       this.elements = new Array();
   };
   //向MAP中增加元素（key, value)
   this.put = function(_key, _value) {
       if(this.containsKey(_key)){
        this.remove(_key);
        this.elements.push( {
           key : _key,
           value : _value
        });
       }else{
        this.elements.push( {
           key : _key,
           value : _value
        });
       }  
   };
   //删除指定KEY的元素，成功返回True，失败返回False
   this.remove = function(_key) {
       var bln = false;
       try {
           for (var i = 0; i < this.elements.length; i++) {
               if (this.elements[i].key == _key) {
                   this.elements.splice(i, 1);
                   return true;
               }
           }
       } catch (e) {
           bln = false;
       }
       return bln;
   };
   //获取指定KEY的元素值VALUE，失败返回NULL
   this.get = function(_key) {
       try {
           for (var i = 0; i < this.elements.length; i++) {
               if (this.elements[i].key == _key) {
                   return this.elements[i].value;
               }
           }
       } catch (e) {
           return false;
       }
       return false;
   };
   //判断MAP中是否含有指定KEY的元素
   this.containsKey = function(_key) {
       var bln = false;
       try {
           for (var i = 0; i < this.elements.length; i++) {
               if (this.elements[i].key == _key) {
                   bln = true;
               }
           }
       } catch (e) {
           bln = false;
       }
       return bln;
   };
  //获取map的所有values
  this.values = function() {
       var arr = new Array();
       for (var i = 0; i < this.elements.length; i++) {
           arr.push(this.elements[i].value);
       }
       return arr;
   };
  //获取map的所有keys
  this.keys= function() {
       var arr = new Array();
       for (var i = 0; i < this.elements.length; i++) {
           arr.push(this.elements[i].key);
       }
       return arr;
   };
   //获取数组
   this.getArray= function(){
   	var arr = new Array();
   	for (var i = 0; i < this.elements.length; i++) {
           arr.push({
	            key : this.elements[i].key,
	            value : this.elements[i].value
	         });
       }
       return arr;
   };
}
//********************************************
var startP=1;
var Formstatus=true;
var tradProdCode=0;
var map=new Map();

$(document).ready(function() {
	loadDiscountType();//加载"折扣系数"下拉列表
	var $prodInstCode = $("#prodInstCode");
	var $tradProdDesc = $("#tradProdDesc");
	var $tradAppType = $("#tradAppType");
	var $unitPp = $("#unitPp");
	var $maxDelayDay = $("#maxDelayDay");
	var $minDelayDay = $("#minDelayDay");
	var $instant = $("#instant");
	var $minDays = $("#minDays");
    var $maxDays = $("#maxDays");
	var $sub = $("#sub");
	var $longestCancelDay =$("#longestCancelDay");
	//最短延时起保天数：不小于0的整数，且首位非0
	$minDelayDay.change(function(){
		if($minDelayDay.val()!=""){
			var minDelayDayReg = new RegExp("^(0|[1-9][0-9]*|-[1-9][0-9]*)$");
			var delayflag = minDelayDayReg.test($minDelayDay.val());
			if(!delayflag) $.message("error","最短延时起保天数必须是整数");
		}
	});

	//最长注销天数
	$longestCancelDay.change(function(){
		if($longestCancelDay.val()!=""){
			var minDelayDayReg = new RegExp("^(0|[1-9][0-9]*)$");
			var delayflag = minDelayDayReg.test($longestCancelDay.val());
			if(!delayflag) $.message("error","最长注销天数必须是大于等于0的整数");
		}
	});
	//最长延时起保天数：不小于0的整数，且首位非0
	$maxDelayDay.change(function(){
		if($maxDelayDay.val()!=""){
			var maxDelayDayReg = new RegExp("^(0|[1-9][0-9]*)$");
			var delayflag = maxDelayDayReg.test($maxDelayDay.val());
			if(!delayflag){
				 $.message("error","最长延时起保天数必须是不小于0的整数");
				 return;
			}
			if(parseInt($minDelayDay.val())>parseInt($maxDelayDay.val())){
				$.message("error","最长延时起保天数不能小于延时起保天数");
				return;
			}
		}
	});
	
	//最短保险天数：大于等于1的正整数
	$minDays.change(function(){
		if($minDays.val()!=""){
			var minDayReg = new RegExp("^[1-9][0-9]*$");
			var minDayflag = minDayReg.test($minDays.val());
			if(!minDayflag) $.message("error","最短保险天数必须是不小于1的整数");
		}
	});

	//最长保险天数：大于等于1的正整数，且必须大于最短保险天数
	$maxDays.change(function(){
		if($maxDays.val()!=""){
			var maxDayReg = new RegExp("^[1-9][0-9]*$");
			var maxDayflag = maxDayReg.test($maxDays.val());
			if(!maxDayflag){
				$.message("error","最长保险天数必须是不小于1的整数");
				return;
			}
			if(parseInt($minDays.val())>parseInt($maxDays.val())){
				$.message("error","最长保险天数不能小于最短保险天数");
				return;
			}
		}
	});
	//最大份数：不小于0的整数，且首位非0
	$unitPp.change(function(){
		if($unitPp.val()!=""){
			var unitPpReg = new RegExp("^(0|[1-9][0-9]*)$");
			var ppflag = unitPpReg.test($unitPp.val());
			if(!ppflag) $.message("error","最大份数必须是不小于0的整数");
		}
	});
});
 
/*-----------------------------2015年6月3日17:27:07-----wangyan------add↓---*/
//获取折扣系数选项
function loadDiscountType(){
	$.ajax({
		url : "product/getDiscountType",
		type : 'POST',
		async : true,
		dataType:'json',
		success:function(discountTypeList){
			if($.validate(discountTypeList))return;
			
			if(null!=discountTypeList && discountTypeList[0]!=undefined){	
				 $.each(discountTypeList,function(i,item){
					$("#adjust").append("<option value="+item.ADJUSTID+">"+item.ADJUSTDESC+"</option>");
				 });
			}
		}
	});
}
function addAdjustDiv(){
	var adjustVal = $("#adjust").val()
	if(adjustVal!=""){
		$("#adjustDiv").append("<div>"+
	  			"<input name='peoplenum' type='text' style='width:55px;' class='input_text'>&nbsp;人&nbsp;<input name='coefficient' type='text'  style='width:55px;' class='input_text'>&nbsp;%&nbsp;&nbsp;<input type='button'  value='-' onclick='removeAdjustDiv(this)'>"
	      		+"</div>");
	}
}
function removeAdjustDiv(o){
	$(o).parent().remove()
}

/*-----------------2015年6月3日17:27:07------wangyan-----add↑-----*/
//表单校验
function checkFormFormate(){
	var $prodName = $("#prodName");
	var $prodType = $("#prodType");
	 if($.trim($prodName.val()).length==0){
    	$.message("error","产品名称不能为空");
    	$prodName.focus();
    	return false;
    } 
	return true; 
}

function addProduct(){
	if(!checkFormFormate())return;
	$.ajax({
		url:"<%=basePath%>creditProduct/saveCreditProd",
		type:'POST',
		data:{
			prodName:$("#prodName").val(),
			prodType:$("#poolType").val(),
			epolicyCode:$("#epolicyCode").val(),
			epolicyTitle:$("#epolicyTitle").val(),
			prodDesc:$("#tradProdDesc").val()
			},
		success:function(obj){
			var a = obj;
			for(var b in a){
				if(b=="codeName"){
					$("#dictName").html(a[b]);
				}else if(b=="tradProdPlan"){
					$("#dictCode").html(a[b].tradPlanCode);
					$("#prodCode").html(a[b].tradProdCode);
					if(a[b].insType==120001){
						$("#insType").html("主险");
					}else{
						$("#insType").html("附险");
					}
				}
			}
			$.dialog({
				type: "success",//success,error
				content: "添加成功 ",
				onOk:function(){
					$("#dicttable").show()
					return;
				},
				onCancel: function() {
					return;
				}
			});
		}
	})
}


function vreset(){
	$("#prodInstCode").val("");
	$("#prodName").val("");
	$("#unitPp").val("");
	$("#maxDelayDay").val("");
	$("#minDelayDay").val("");
	$("#minDays").val("");
	$("#maxDays").val("");
	$("#tradProdDesc").val("");
	$("#tradAppType").find("option[value='0']").attr("selected",true);
	$("#instant").find("option[value='N']").attr("selected",true);
	$("#epolicyCode").val("");
	$("#epolicyTitle").val("");
	$('#poolType').val("");
	$("#prodType").val(0);
	$("#ageLimit").val("");
	$("#maxAge").val('');
	$("#minAge").val('');
	$("#maxAge").attr('readOnly',true);
	$("#minAge").attr('readOnly',true);
	$("#maxAge").css('background-color','#ccc');
	$("#minAge").css('background-color','#ccc');
	$("#maxOccupLevel").val("");
	$("#insuredNoLimit").val("");
	$("#minInsuredNo").val("");
	$("#minInsuredNo").attr('readOnly',true);
	$("#minInsuredNo").css('background-color','#ccc');
	/* $("#agentType").val(0); */
	
}
	
	function delTradProdDict(obj){
		$.dialog({
			type: "warn",//success,error
			content: "您确定要删除该产品吗？",
			onOk: function() {
				var editTr = $(obj).parent('td').parent('tr')[0];
				var flag=2;
				var tradProdCode = editTr.childNodes[flag].innerHTML;
				deleteTradProdInst(tradProdCode);
			}
		});
	}
	function deleteTradProdDict(tradProdCode){
		$.openLoading();
		$.ajax({
			url : "creditProduct/deProdDictInfo?"+new Date().getTime(),
			type : 'POST',
			data:{
				prodCode:tradProdCode
			},
			success : function(obj) {
				$.closeLoading();
				if($.validate(obj))return;
				loadCreditProductData(1);
			}
		});
	}
</script>
<style type="text/css">
.ui-icon {
	display: block;
	text-indent: -99999px;
	overflow: hidden;
	background-repeat: no-repeat
}
</style>
</head>
<body>
	<div class="current">
		<table class="current_table_1">
			<tbody>
				<tr class="f2">
					<td><img src="./images/current_1.jpg"></td>
					<td class="current_table_1_td"><img src="images/current_1.png">&nbsp;您现在的位置：&nbsp;
						<span style="color: #136bab;">信保产品管理 <span
							style="padding: 0 5px; font-weight: bold; line-height: 28px;">&gt;</span>产品配置
							<span
							style="padding: 0 5px; font-weight: bold; line-height: 28px;">&gt;</span>新增产品
					</span></td>
					<td><img src="./images/current_3.jpg"></td>
				</tr>
			</tbody>
		</table>
	</div>

	<form id="inputForm" >
		<table class="table_05">
			<tbody>
				<tr>
					<td colspan="4"
						style="font-size: 12px; font-weight: bold; text-align: left; color: #3876bf; line-height: 17px; background-image: url(images/centent_1.jpg)">新增产品</td>
				</tr>
				<tr>
					<th width="25%">产品名称：</th>
					<td width="28%"><input name="prodName" id="prodName"
						type="text" class="input_text"><span class="red">*</span>&nbsp;
					<th width="20%">产品归类：</th>
					<td width="22%"><select id="poolType" class="select_1"
						style="visibility: visible;">
							<option value="">---请选择---</option>
							<c:forEach var="polPoolType" items="${polPoolType}">
								<option value="${polPoolType.code}">${polPoolType.codeName}</option>
							</c:forEach>
					</select><span class="red">*</span></td>
				</tr>
				 <%--  <tr>
	               	  <th>最短延时起保天数：</th>
	                  <td><input name="minDelayDay"  id="minDelayDay" type="text" maxlength="5" class="input_text"><span class="red">*</span><span class="blue">支持负数</span></td>
	                  <th>最长延时起保天数：</th>
	                  <td><input name="maxDelayDay"  id="maxDelayDay" type="text" maxlength="5" class="input_text"><span class="red">*</span></td>
	              </tr>
	              <tr>
	              	  <th>最长起保后注销天数：</th>
	                  <td><input name="longestCancelDay"  id="longestCancelDay" type="text" maxlength="5" class="input_text" value="0"><span class="red">*</span></td>
	                 <th>保险期间：</th>
	                 <td>
		                 <input name="minDays" id="minDays" type="text" maxlength="5"  class="input_text" style="width:60px;">&nbsp;至&nbsp;
		                 <input name="maxDays" id="maxDays" type="text" maxlength="5"  class="input_text" style="width:60px;">&nbsp;&nbsp;
		                 <select name="PPP_UNIT" id="PPP_UNIT" class="select_1"  style="width:55px;visibility: visible;">
		                 	<c:forEach var ="periodType" items="${insurePeriodList}">
	                  			<option value="${periodType.code}">${periodType.codeName}</option>
	                  		</c:forEach>
		                 </select><span class="red">*</span>
	                 </td>
	              </tr>
				<tr>
					<th>电子保单模板：</th>
					<td><select id="epolicyCode" name='epolicyCode' onchange="" class="select_1"
						style="visibility: visible;">
							<option value="">----请选择----</option>
							<c:forEach var="epolicy" items="${epolicys}">
								<option value="${epolicy.code}">${epolicy.code}-${epolicy.codeName}</option>
							</c:forEach>
					</select></td>
					<th>电子保单标题：</th>
					<td><input type="text" class="input_text" id='epolicyTitle' name ='epolicyTitle'></td>
				</tr>
				 <tr>
	              	  <th>是否立项：</th>
	                  <td>
	                  	<select class="select_1"style="visibility: visible;width:100px;" id="isSocial">
	                  		<option value="001">是</option>
	                  		<option value="000">否</option>
	                  	</select>
	                  </td>
	  				  <th></th>
	              </tr>  --%>
				<tr>
					<th>交易系统产品描述：</th>
					<td colspan="3"><textarea name="tradProdDesc"
							id="tradProdDesc" maxlength="50" rows="5" class="textarea_1"
							style="resize: none"></textarea><!-- <span class="red">*</span> --></td>
				</tr>
			</tbody>
		</table>
		<div align="center">
			<input id="sub" class="input_button_1" name="" type="button"
				value="确定" onclick="addProduct()">&nbsp;&nbsp; 
			<input class="input_button_1" name="" onclick="vreset()" type="button"
				value="重置">
		</div>
	</form>
	<div style="margin-top: 5px;">
		<table class="table_02" id="ProdPlan" align="center">
			<tbody>
				<tr>
					<td colspan="6"
						style="font-size: 12px; font-weight: bold; text-align: left; color: #3876bf; line-height: 27px; height: 27px; background-image: url(images/centent_1.jpg)">&nbsp;险别配置</td>
				</tr>
				<tr>
					<td>
						<table id="ProdPlanTable" class="content_table_1">
							<thead>
								<tr class="f1">
									<th style="width: 10%">序号</th>
									<th style="width: 25%">险别代码</th>
									<th style="width: 25%">险别名称</th>
									<th style="width: 20%">主/附标识</th>
								<!-- 	<th style="width: 20%">操作</th> -->
								</tr>
							</thead>
							<tbody id="dicttable" style='display:none'>
								<tr>
									<td id="number">1</td>
									<td id="prodCode" style="display:none;"></td>
									<td id="dictCode"></td>
									<td id="dictName"></td>
									<td id="insType"></td>
									<!-- <td id="do">
										<a href='javascript:void(0)' onClick='editTradProdDict(this);return false'>编辑</a>&nbsp<a href='javascript:void(0)' onClick='delTradProdDict(this);return false'>删除</a>
									</td> -->
								</tr>
							</tbody>
						</table>
					</td>
				</tr>
			</tbody>
		</table>
	</div>
</body>
</html>